package proxy05;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.Date;

public class HandlerImpl implements InvocationHandler {

	private LaoWang lw = new LaoWang();

	/**
	 *
	 * @param proxy
	 * @param method
	 * @param args
	 * @return
	 * @throws Throwable
	 */
	@Override
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		/**
		 * method:此时封装getSum信息
		 * args:此时封装传递过来的参数 7,12
		 */
		System.out.println("当前被代理方法的信息:"+method);
		System.out.println("当前传递过来的参数");
		for (Object arg : args) {
			System.out.println(arg);
		}
		Object returnVal = method.invoke(lw,args);//相当于 Object returnVal =lw.getSum(7,12)
		System.out.println("调用完该方法的返回值"+returnVal);
		return returnVal;
	}
}
